import Vue from 'vue'
import App from './App'

//路由对象
import Router from "vue-router"
Vue.use(Router);
var routes = require('@'+ process.env.PROJECT +'/router');
var router = new Router(routes);

//状态管理对象
import Vuex from 'vuex';
Vue.use(Vuex);
var storeData  = require('@'+ process.env.PROJECT +'/store')
var store = new Vuex.Store(storeData)

//element-ui插件
import './style/element/theme/index.css'
import elementUI from 'element-ui'
// import './style/element-variables.scss'
Vue.use(elementUI);

// 内容框
var mainBox  = require('@'+ process.env.PROJECT +'/components/common/main_box')
Vue.component('main-box',mainBox.default);

// 弹出框
var dialogBox  = require('@/components/common/dialog_box')
Vue.component('dialog-box',dialogBox.default);

//动画插件
import animate from 'animate.css' 
Vue.use(animate)

//复制到粘贴板
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

//IE兼容性处理
import 'babel-polyfill'

//vuex,jquery,echarts插件
import jquery from 'jquery'
import echarts from 'echarts'
import md5 from 'js-md5';
import CryptoJS from 'crypto-js';

//保存到全局属性中
window.router = router;
window.store = store;
window.$ = jquery;
window.jQuery = jquery;
window.$echarts = echarts;
window.md5 = md5;
window.CryptoJS = CryptoJS;

//自定义js : 保存了全局属性axios, config, lsKey, tool, api
import './js/utils/frame.js'
import './js/utils/axios.js'
require('@'+ process.env.PROJECT +'/js/api/api.js');

//请求处理权限
require('./permission.js')

Vue.config.productionTip = false


Vue.prototype.hasApi = function(apiName) {
	//当前路径和接口列表
	var path = this.$route.path;
	var urls = [];
	//获取权限对象,遍历
	var permit = store.state.permit;
	for(let k in permit) {
		//找到当前路径下的有权限的接口路径列表
		if(path == permit[k].path) {
			urls = permit[k].urls;
			break;
		}
	}
	//根据接口别名获取接口路径,判断是否在权限列表中
	var url = apiMap[apiName].url;
	return (urls.indexOf(url) >= 0);
}

Vue.prototype.hasPage = function(pageId) {
	var permit = store.state.permit;
	return (permit[pageId] != null);
}

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
